﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QxFramework.Utilities;
using QxFramework.Core;
using System;

public class M_Shot : SkillBase
{
    public float damageRatio = 1;
    public float manaCost = 10;
    new public Mage User
    {
        get => (Mage)base.User;
        set => base.User = value;
    }
    public override void Init(EntityBase user)
    {
        base.Init(user);
        ColdDownInit();

        User = GameObject.FindGameObjectWithTag("Player").GetComponent<Mage>();
        //rb = Player.time.rigidbody2D;

        MessageManager.Instance.Get<M_Shot_Event>().RegisterHandler(M_Shot_Event.Stop, Stop);
        MessageManager.Instance.Get<M_Shot_Event>().RegisterHandler(M_Shot_Event.Damage, Damage);

    }
    public override void FixedUpdate()
    {
        if (!isColddown)
        {
            if (Input.GetKey(KeyCode.Mouse0))
            {
                if (User.parameter.ManaData.CurrentMana >= manaCost)
                {
                    //Debug.Log("attack");
                    for (int i = 1; i <= User.orbPack.orbCount; i++)
                    {
                        EffectManager.Instance.InstantiateSkillEffect("BulletTest", EffectManager.Instance.transform.GetChild(0), User.orbPack.orbPos[i].transform.position, User.GetMousePos_Orb(i), this);
                    }
                    User.parameter.ManaData.currentMana -= manaCost;

                    isColddown = true;
                }
                
            }
        }

        ColdDownCheck();
    }

    public void Stop(object sender, EventArgs args)
    {

    }
    public void Damage(object sender, EventArgs args)
    {
        if (args is AttackInfo arg)
        {
            foreach (EntityBase enemy in arg.targets)
            {
                enemy.parameter.HealthData.currentHealth -= User.parameter.StatusPointData.attack * damageRatio;
            }
        }
        //var enemys = Physics2D.BoxCastAll(Player.transform.position, new Vector2(1,1), 0,Player.parameter.MovementData.moveDir);
        Debug.Log("hit!");
    }
    
}
public enum M_Shot_Event
{
    Damage,
    Stop,
}
